/**
 * Project Name:mauto-web
 * File Name:ApiAutoConfigController.java
 * Package Name:com.inftech.mauto.sys.web.front
 * Date:2016年10月17日下午9:48:11
 * Copyright (c) 2016, inf-technology Co., Ltd. All Rights Reserved.
 *
*/

package com.inftech.mauto.sys.web.front;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.inftech.mauto.common.base.BaseController;
import com.inftech.mauto.common.base.BusinessException;
import com.inftech.mauto.common.constant.HttpStatusCodeEnum;
import com.inftech.mauto.sys.service.CarBasicService;

/**
 * ClassName:ApiCarBasicController <br/>
 * Function: 车型选择接口. <br/>
 * Date: 2016年10月17日 下午9:48:11 <br/>
 * 
 * @author jeno
 * @version
 * @since JDK 1.7
 */
@Controller
@RequestMapping("/api/carBasic")
public class ApiCarBasicController extends BaseController {

	/**
	 * 注入车型业务层
	 */
	@Autowired
	protected CarBasicService carBasicService;

	/**
	 * 
	 * brandList:获取品牌列表. <br/>
	 *
	 * @author puyf
	 * @param request
	 * @since JDK 1.7
	 */
	@RequestMapping(value = "/carBrand/list", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String brandList(HttpServletRequest request) throws Exception {
		String outJson = "";
		try {
			// 获取品牌列表
			Map<String, List<Map<String, Object>>> carBrandList = carBasicService.queryCarBrandList();
			LOG.info("获取车辆品牌列表成功");
			// 返回结果
			HttpStatusCodeEnum statusCode = HttpStatusCodeEnum.STATUS_CODE_200;
			outJson = getOutJson(statusCode, true, statusCode.toString(), carBrandList);
		} catch (Exception e) {
			if (e instanceof BusinessException) {
				throw e;
			}
			LOG.error("获取车辆品牌列表失败", e);
			HttpStatusCodeEnum statusCode = HttpStatusCodeEnum.SCOPE_BASE;
			outJson = getOutJson(statusCode, false, statusCode.toString(), null);
		}
		return outJson;
	}

	/**
	 * 
	 * modelList:获取车型列表. <br/>
	 *
	 * @author puyf
	 * @param id
	 * @param request
	 * @return
	 * @throws Exception
	 * @since JDK 1.7
	 */
	@RequestMapping(value = "/carModel/list/{cbId}", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String modelList(@PathVariable int cbId, HttpServletRequest request) throws Exception {
		String outJson = "";
		try {
			// 获取品牌列表
			Map<String, Object> carModelList = carBasicService.queryCarModelList(cbId);
			LOG.info("获取车辆型号列表成功");
			// 返回结果
			HttpStatusCodeEnum statusCode = HttpStatusCodeEnum.STATUS_CODE_200;
			outJson = getOutJson(statusCode, true, statusCode.toString(), carModelList);
		} catch (Exception e) {
			if (e instanceof BusinessException) {
				throw e;
			}
			LOG.error("获取车辆型号列表失败", e);
			HttpStatusCodeEnum statusCode = HttpStatusCodeEnum.SCOPE_BASE;
			outJson = getOutJson(statusCode, false, statusCode.toString(), null);
		}
		return outJson;
	}
}
